﻿using SIG.Model.Shipping;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;


namespace SIG.Model.Mapping
{
    public class RecipientInfoMap : EntityTypeConfiguration<RecipientInfo>
    {
        public RecipientInfoMap()
        {
            this.HasKey(p => p.Id);

            this.Property(p => p.Id)
                .HasColumnName("Id")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.ToTable("RecipientInfoSet");

            this.Property(p => p.Address).HasMaxLength(250).IsRequired();
            this.Property(p => p.ProvinceId).IsRequired();
            this.Property(p => p.Recipient).HasMaxLength(50).IsRequired();
            this.Property(p => p.Mobile).HasMaxLength(50).IsRequired();
            this.Property(p => p.Phone).IsOptional();
            this.Property(p => p.CreatedDate).IsRequired().HasColumnType("datetime");
            this.Property(p => p.CreatedBy).HasMaxLength(50);
            this.Property(p => p.UpdatedDate).IsOptional().HasColumnType("datetime");
            this.Property(p => p.UpdatedBy).IsOptional().HasMaxLength(50);

            this.HasRequired(p => p.Province)
           .WithMany(h => h.RecipientInfoes)
           .HasForeignKey(p => p.ProvinceId);

            this.HasRequired(p => p.City)
            .WithMany(h => h.RecipientInfoes)
            .HasForeignKey(p => p.CityId);

            this.HasRequired(p => p.District)
            .WithMany(h => h.RecipientInfoes)
            .HasForeignKey(p => p.DistrictId);
        }
    }
}
